<%@page import="com.jfinal.kit.PropKit" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" import="cn.com.dashihui.web.common.OrderCode" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>积分抵现</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
      <style type="text/css">
			table td{
			text-align: center;
			white-space: normal; 
			overflow: hidden;
		    text-overflow: ellipsis;
			}
		 	table th{
			text-align: center;
		 	}
	</style>
</head>
<body>
<div id="wrapper"  class="row">
	
			<div class="col-lg-12">
				<h1 class="page-header">抵现明细</h1>
			</div>
		<!-- 搜索框 -->
			<div class="title-top col-lg-12">
				<label class="search-label">买家电话：</label><input type="text" id="sTel" value="" class="form-control search-input width200" maxlength="13">
				
				<label class="search-label">选择公司：</label>
				    <select id="sSellerId" class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%">
						<c:forEach items="${list }" var="seller">
							<option value="${seller.sellerId }">${seller.sellerName }</option>
						</c:forEach>
				    </select>
				<label class="search-label">选择分公司：</label>
				<select id="sStoreId" class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%" >
					<c:forEach items="${listStore }" var="store">
						<option value="${store.storeid }">${store.title }</option>
					</c:forEach>
				</select>
				 <label class="search-label">选择销售：</label><input type="text" id="toBossOneId" value="" class="form-control search-input width200" maxlength="13">
			
					<shiro:hasPermission name="bus:user:dixian:doExcel">
				     <button onclick="doExcel();"  class="btn btn-success pull-right">导出</button>
				    </shiro:hasPermission>
				<div class="clearfix"></div>
			</div>
			<div class="title-top col-lg-12">
			   <%-- <select id="sStoreId" class="selectpicker pull-left p-l-5" data-width="10%" data-url="${BASE_PATH}/api/storeAll" data-isfirst="true"   data-key="storeid:title"></select>  --%>
				<label class="search-label">消费时间：</label><input type="text" id="sBeginDate" autocomplete="off" value="" class="form-control search-input width200 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">至</label><input type="text" id="sEndDate" autocomplete="off" value="" class="form-control search-input width200 datetimepicker" data-format="yyyy-mm-dd" >
				<button class="btn btn-success search-btn" onclick="query();">确定</button>
				<button class="btn btn-success search-btn" onclick="reset();">重置</button>
				<div class="clearfix"></div>
			</div>
			<div class="col-lg-12 title-top">
				<div class="col-lg-12">
						<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
				
				</div>
			<!-- table-responsive表格的下编框的滚动条 -->
		<div class="table-responsive panel panel-default ">
			<table id="dataTable" class="table  table-hover table-noellipsis table-bordered" style="  overflow:scroll;">
				<thead>
				<tr>
					<th width="300px">消费分公司</th>
					<th width="300px">所属公司</th>
					<th width="100px">会员姓名</th>
					<th width="150px">联系方式</th>
					<th width="300px">开卡分公司</th>
					<th width="100px">销售</th>
					<th width="500px">消费项目</th>
					<th width="200px">消费金额</th>
					<th width="100px">抵现金额</th>
					<th width="180px">消费时间</th>
				</tr>
			</thead>		 
			   <tbody id="dataList"></tbody>
		 </table>
		</div>
	       	<div class="col-lg-12">
	       		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
	       	</div>
       </div>

</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
	   {{each list as item}}
				 <tr id="item{{item.orderNum}}" data-id="{{item.orderNum}}">
					<td>{{item.title}}</td>
					<td>{{item.sellerName}}</td>
					<td>{{item.name}}</td>
					<td>{{item.phone}}</td>
					<td>{{item.store}}</td>
					<td>{{item.toBossOneId}}</td>
					<td>{{item.mun}}</td>
					<td>{{item.money}}</td>
					<td>{{item.amount}}</td>
					<td>{{item.date}}</td>
				</tr>
	{{/each}}
</script>
<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	var  sSellerId = $("#sSellerId").val(),sStoreId = $("#sStoreId").val();
	var sell,store;
	if(sSellerId !=null && sSellerId !="" && sSellerId !=undefined){
		sell=sSellerId.join("','");
	}
	if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
		store=sStoreId.join("','");
	}
	var params = {
		pageSize:10,
		toBossOneId:$("#toBossOneId").val(),
		beginDate:$("#sBeginDate").val(),
		endDate:$("#sEndDate").val(),
		phone:$("#sTel").val(),
		sellerId:sell,
		storeId:store
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/bus/order/dixianpage",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}

function doExcel(){
	
     	 var toBossOneId=$("#toBossOneId").val(),beginDate = $("#sBeginDate").val(),endDate = $("#sEndDate").val(), phone = $("#sTel").val(),sSellerId=$("#sSellerId").val(),sStoreId = $("#sStoreId").val();
     	var sell="",store="";
    	if(sSellerId !=null && sSellerId !="" && sSellerId !=undefined){
    		sell=sSellerId.join("','");
    	}
    	if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
    		store=sStoreId.join("','");
    	}
     	 window.location.href="${BASE_PATH}/bus/order/doDixianExcel?toBossOneId="+toBossOneId+"&beginDate="+beginDate+"&endDate="+endDate+"&phone="+phone+"&sellerId="+sell+"&storeId="+store;
	};
	$("#sBeginDate").datetimepicker({
	    format: 'yyyy-mm-dd hh:ii:ss',
	    minuteStep:1,
	    minView:'hour',
	    language: 'zh-CN',
	    pickerPosition:'bottom-right',
	    autoclose:true,
	}).on("click",function(){
		var d2=new Date();
		var d=$("#sEndDate").val();
		if(d==""){
			 $("#sBeginDate").datetimepicker("setEndDate",d2);
		}else{
			var d1=new Date(d); 
			d1.setDate(d1.getDate()-1);
			if(d1>d2){
		  	 	 $("#sBeginDate").datetimepicker("setEndDate",d2);
			}else{
				 $("#sBeginDate").datetimepicker("setEndDate",d1);
			}
		}
	});

	$("#sEndDate").datetimepicker({
	    format: 'yyyy-mm-dd hh:ii:ss',
	    minuteStep:1,
	    minView:'hour',
	    language: 'zh-CN',
	    autoclose:true,
		}).on("click",function(){
			var d=$("#sBeginDate").val();
			var d1=new Date(d); 
			d1.setDate(d1.getDate()+1); 
			$("#sEndDate").datetimepicker("setStartDate",d1);
		});
		
	 $(document).on("click","#sEndDate",function(){
	    	$('#sEndDate').datetimepicker('show');
	    });

	$(document).on("click","#sBeginDate",function(){
		$('#sBeginDate').datetimepicker('show');
	});
	function reset(){
		$("#sBeginDate").val("");$("#sEndDate").val("");$("#sTel").val(""); $("#sStoreId").val("");$("#sStoreId").trigger("change");
		$("#toBossOneId").val("");$("#sStoreId").selectpicker("refresh"); 
		$("#sSellerId").val("");$("#sSellerId").trigger("change");  $("#sStoreId").val("");$("#sStoreId").trigger("change"); 
		$("#sStoreId").selectpicker("refresh"); $("#sSellerId").selectpicker("refresh");
	}
	$("#sSellerId").change(function(){
	 var sSellerId=[];
	  sSellerId=$("#sSellerId").val();
	  $.ajax({
               type: "POST",
               url: "${BASE_PATH}/bus/goods/base/chooseStore",
               data: {"sSellerId" : sSellerId},
               dataType: "json",
               traditional: true,
               success: function(data){
              	 $("#sStoreId").empty();
                         for(var i=0; i<data.object.length;i++){
                        	 $("#sStoreId").append("<option value='"+data.object[i].storeid+"'>"+data.object[i].title+"</option>");
                         }
                         $("#sStoreId").selectpicker("refresh");
                     }
           });
      });
</script>
</body>
</html>